import { IChatState, friedsLists, IChatRecord } from "./types"
import CacheLocal from "@/utils/cacheLocal"
import { MutationTree } from "vuex"

// 用 MutationTree 泛型给对象中函数形参 state 赋予类型
const mutations: MutationTree<IChatState> = {
  saveChatFriendList(state, payload: friedsLists[]) {
    state.chatFriendLists = payload
  },

  changeCurrentChatFriend(state, payload: number) {
    state.currentChatId = payload
  },
  //切换当前好友对话
  changeCurrentChat(state, payload: IChatRecord) {
    state.currentChatRecords = payload
    console.log("保存", payload)
  }
}

interface IChatMutations {
  saveChatFriendList: (state: IChatState, payload: friedsLists[]) => void
  changeCurrentChat: (state: IChatState, payload: number) => void
}

export { mutations, IChatMutations }
